import request from "@/http/serve";
import { post, get, deleteR, patch } from "@/http/request";

//响应数据接口类型定义
export interface ApiResponse<T> {
	code: number;
	message: string;
	data: T;
}

export type LoginData = {
	username: string;
	password: string;
};

export type LoginResult = {
	username: string;
	accessToken: string;
	roles: string[];
};

// export const userLogin = async (data: LoginData) => {
// 	return post<LoginResult>({}, "/login", data);
// };

const userLogin = (data: LoginData) => request.post<any, any>("/login", data);

const uploadFile = async (data: any) =>
	post<any>(
		{
			headers: {
				"Content-Type": "multipart/form-data",
			},

			onUploadProgress: (progressEvent) => {
				const percentCompleted = Math.floor((progressEvent.loaded * 100) / progressEvent.total);
				// console.log(percentCompleted); // 这里会打印上传进度百分比
			},
		},
		"/upload/avatar",
		data,
	);

export { userLogin, uploadFile };
